/**
 * 
 */
package org.starsource.forum.server.web;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.web.context.WebApplicationContext;

/**
 * @author james
 *
 */
public class SpringHttpServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1232660454636189811L;

	private WebApplicationContext springContext;
	
	@Override
	public void init(ServletConfig Config) throws ServletException {
		
		super.init(Config);
	
		springContext = (WebApplicationContext) Config
		.getServletContext()
		.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	
		if (springContext == null) {
			throw new RuntimeException("Check Your Web.Xml Setting, No Spring Context Configured");
		}
		
		springContext
		.getAutowireCapableBeanFactory()
		.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);

	}
	
}
